<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px" style="margin-top: 20px">
      <el-form-item label="账号" prop="proCode">
        <el-input v-model="queryParams.account" placeholder="账号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="消费卷名称" prop="productName">
        <el-input v-model="queryParams.couponName" placeholder="消费卷名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="消费卷类型" prop="sourceId">
        <el-select v-model="queryParams.type" filterable placeholder="消费卷类型" style="">
          <el-option v-for="item in donate_option" :key="item.id" :label="item.donateName" :value="item.id"
                     @keyup.enter.native="handleQuery">
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="出入库标志" prop="inventoryFlag" label-width="90px">
        <el-input v-model="queryParams.inventoryFlag" placeholder="请输入出入库标志" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['supermarket:inventory:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['supermarket:inventory:remove']">删除</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['supermarket:inventory:export']"
        >导出</el-button>
      </el-col> -->

    <el-table v-loading="loading" :data="inventoryList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column type="index" width="50" />
      <el-table-column label="账号" align="center" prop="couponName" />
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="昵称" align="center" prop="couponName" />
      <el-table-column label="电话号码" align="center" prop="phone" />
      <el-table-column label="消费卷类型" align="center" prop="type">
        <template slot-scope="scope">
          <el-tag >
            {{ scope.row.type == 1?'满减卷':'折扣卷' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="消费卷名称" align="center" prop="couponName" />
      <el-table-column label="金额设置" align="center" prop="updateTime" width="180">
      </el-table-column>
      <el-table-column label="积分价值" align="center" prop="pointWorth" />
      <el-table-column label="用卷状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag >
            {{ scope.row.status == 1?'已使用':'未使用' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="领卷时间" align="center" prop="gainDatetime" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList" />
  </div>
</template>

<script>
import { listInventory, getInventory, delInventory, addInventory, updateInventory, addOutInventory,getInventoryByCode } from "@/api/supermarket/inventory";
import { donateList } from '@/api/donate/source'
import { couponpage } from '@/api/marketing'
// import { getProductByBarcode } from '@/api/supermarket/scencExchange'

export default {
  name: "Inventory",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品库存表格数据
      inventoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        account: null,
        couponName: null,
        type: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //捐赠来源list
      donate_option: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品库存列表 */
    getList() {
      this.loading = true;
      couponpage(this.queryParams).then(response => {
        this.inventoryList = response.pageData;
        console.log(this.inventoryList)
        this.total=parseInt(response.total) ;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        color: null,
        integratedWorth: null,
        inventory: null,
        inventoryFlag: null,
        outboundNumber: null,
        outboundReason: null,
        proCode: null,
        productName: null,
        size: null,
        sourceId: null,
        specifications: null,
        timeInterval: null,
        timeSlot: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.queryParams)
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品库存";
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids
    //   getInventory(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改商品库存";
    //   });
    // },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          // if (this.form.id != null) {
          //   updateInventory(this.form).then(response => {
          //     this.$modal.msgSuccess("修改成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // } else {
          addOutInventory(JSON.stringify(this.form)).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
          // }
        }
      });
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.id || this.ids;
    //   this.$modal.confirm('是否确认删除商品库存编号为"' + ids + '"的数据项？').then(function () {
    //     return delInventory(ids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => { });
    // },
    /** 导出按钮操作 */
    handleExport() {
      this.download('supermarket/inventory/export', {
        ...this.queryParams
      }, `inventory_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
